<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Z-7
  Date: 2022/3/2
  Time: 13:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form>
    <input type="hidden" name="pageNum" value="${page.pageNum}">
    名称高亮：<input type="text" name="name" value="${name}"><br>
    价格区间：<input type="text" name="min" value="${min}">---<input type="text" name="max" value="${max}">
    <button type="button" onclick="esSearch()" class="btn btn-success">查询</button>
</form>
<table class="table table-hover">
    <thead>
    <tr>
        <th scope="col">商品编号</th>
        <th scope="col">商品名称</th>
        <th scope="col">商品简介</th>
        <th scope="col">价格</th>
        <th scope="col">图片</th>
        <th scope="col">图片介绍</th>
        <th scope="col">上架时间</th>
        <th scope="col">归属人</th>
        <th scope="col">品牌</th>
        <th scope="col">分类</th>
        <th scope="col">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${page.list}" var="good">
        <tr>
            <th>${good.id}</th>
            <td>${good.name}</td>
            <td>${good.title}</td>
            <td>${good.price}</td>
            <td><img src="http://localhost/img/${good.picture}" width="80px" height="80px"></td>
            <td>
                <video src="http://localhost/img${good.viedo}"width="100px" height="100px"/>
            </td>
            <td>
                <fmt:formatDate value="${good.createTime}" pattern="yyyy-MM-dd"/>
            </td>
            <td>${good.userName}</td>
            <td>${good.brandName}</td>
            <td>${good.catName}</td>
            <td>
                <button type="button" class="btn btn-warning" onclick="to_del(${good.id})">删除</button>
                <button type="button" class="btn btn-info" onclick="to_update(${good.id})">修改</button>
                <button type="button" class="btn btn-light">详情</button>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="100">
            <button type="button" onclick="exportPDF(1)" class="btn btn-outline-dark">预览PDF</button>
            <button type="button" onclick="exportPDF(0)" class="btn btn-outline-dark">导出PDF</button>
            <button type="button" onclick="to_add()" class="btn btn-success">新增商品</button>
        </td>
    </tr>
    <tr>
        <td colspan="100">
            <button type="button" onclick="goPage(1)" class="btn btn-outline-warning">首页</button>
            <button type="button" onclick="goPage(${page.pageNum == 1 ? 1 : page.pageNum - 1})" class="btn btn-outline-info">上一页</button>
            <button type="button" onclick="goPage(${page.pageNum == page.pages ? page.pages : page.pageNum + 1})" class="btn btn-outline-secondary">下一页</button>
            <button type="button" onclick="goPage(${page.pages})" class="btn btn-outline-dark">尾页</button>
        </td>
    </tr>
    </tbody>
</table>
<jsp:include page="goods_add.jsp"/>

<script type="text/javascript">
    function goPage(pageNum) {
        $('[name="pageNum"]').val(pageNum);
        enterFun("${pageContext.request.contextPath}/goods/list?"+$("form").serialize());
    }
    function exportPDF(mode) {
        window.open("${pageContext.request.contextPath}/goods/exportPDF?mode="+mode);
    }
    function to_add() {
        $('#add').modal('show');
    }
    function to_del(id) {
        $.post("/goods/to_del",{id:id},function (flag) {
            if(flag){
                alert("删除成功");
                enterFun("${pageContext.request.contextPath}/goods/list?"+$("form").serialize());
            }
        })
    }
    function to_update(id) {
        enterFun("${pageContext.request.contextPath}/goods/to_update?id="+id);
    }
    function esSearch() {
        enterFun("${pageContext.request.contextPath}/goods/esList?name="+$("[name='name']").val()+"&min="+$("[name='min']").val()+"&max="+$("[name='max']").val());
    }
</script>
